package com.mlnx.push.websocket;

import com.mlnx.mptp.push.PushPacket;
import com.mlnx.push.MlnxPushClientService;
import com.mlnx.push.websocket.client.PushClient;
import com.mlnx.service.base.properties.PushProperties;

import java.util.Random;

/**
 * Created by amanda.shan on 2019/10/31.
 */
public class WebsocketMlnxPushClientService implements MlnxPushClientService {

    private PushClient pushClient;

    @Override
    public void init(PushProperties pushProperties) throws Exception {

        pushClient = new PushClient("server-" + (new Random().nextInt()), "123456",
                pushProperties.getPushServerIp(),
                pushProperties.getWebsocketPushPort(),
                pushProperties.getSendTimeoutMillis());
    }

    @Override
    public void push(String topic, PushPacket packet) {

        packet.getBody().setTopic(topic);
        pushClient.push(packet);
    }
}
